package com.itheima.mall.web.oms;

import com.itheima.mall.dto.OrderDto;
import com.itheima.mall.pojo.oms.OmsOrder;

import com.itheima.mall.pojo.oms.OmsOrderItem;
import com.itheima.mall.service.oms.OrderService;
import com.itheima.mall.vo.OrderDetailVo;
import com.itheima.mall.vo.PageResult;
import com.itheima.mall.vo.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;

@RestController
@RequestMapping("order")
public class OrderController {
    @Autowired
    private OrderService orderService;

/*
*
     * 批量删除订单
     * @return

*/


    @PostMapping("delete")
    public R deleteOrderByIds(@RequestParam Integer[] ids){
        orderService.deleteOrderByIds(ids);
        return R.succeed(null,null);
    }

/*

*
     * 查询订单
     * @param orderDto
     * @return
*/
    @GetMapping("/list")
    public R listOrder(OrderDto orderDto){
        PageResult result=orderService.listOrder(orderDto);
        return R.succeed(result,null);
    }


/*
*
     * 批量关闭订单
     * @param ids
     * @param note
     * @return

*/

    @PostMapping("/update/close")
    public R closeOrder(@RequestParam(value = "ids") Integer[] ids,String note){
        orderService.closeOrder(ids,note);
        return R.succeed(null,null);
    }


/*
*
     * 批量发货
     * @param
     * @param
     * @return


*/
    @PostMapping("/update/delivery")
    public R deliveryOrder(@RequestBody HashMap deliveryParamList){
        orderService.deliveryOrder(deliveryParamList);
        return R.succeed(null,null);
    }

/*
*
     * 修改订单费用信息
     * @param moneyInfoParam
     * @return

*/

    @PostMapping("update/moneyInfo")
    public R updateMoneyInfo(@RequestBody HashMap moneyInfoParam ){
        orderService.updateMoneyInfo(moneyInfoParam);
        return R.succeed(null,null);
    }


/*

*
     * 备注订单
     * @param id
     * @param note
     * @param status
     * @return
*/
    @PostMapping("update/note")
    public R updateNote(@RequestParam(value = "id") Integer id,
                        String note,
                        @RequestParam(value = "status") Integer status){
        orderService.updateNote(id,note,status);
        return R.succeed(null,null);
    }

/*
*
     * 修改收货人信息
     * @param receiverInfoParam
     * @return

*/
    @PostMapping("update/receiverInfo")
    public R updateReceiverInfo(@RequestBody OmsOrder omsOrder){
        orderService.updateReceiverInfo(omsOrder);
        return R.succeed(null,null);
    }

    /**
     * 获取订单详情：订单信息、商品信息、操作记录
     * @param id
     * @return
     */
    @GetMapping("/{id}")
    public R orderList(@PathVariable Integer id){
        OrderDetailVo orderDetailVo = orderService.orderList(id);
        return R.succeed(orderDetailVo,null);

    }


}
